package com.servlet;

import com.dao.imp.FindGoodsDaoImp;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;

/**
 * @author Mathison
 * @Title: ${NAME}
 * @Package: ${PACKAGE_NAME}
 * @Description: TODO
 * @date 2021/11/28 15:09
 **/

@WebServlet(name = "CheckSingleItemServlet", value = "/CheckSingleItemServlet")
public class CheckSingleItemServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=utf-8");
        HttpSession session = request.getSession();
        int user_id = Integer.parseInt(session.getAttribute("userId").toString());

        int good_id = Integer.parseInt(request.getParameter("id"));
        int count = Integer.parseInt(request.getParameter("count"));

        String sql = "SELECT * FROM goods WHERE good_id="+good_id;
        FindGoodsDaoImp findGoodsDaoImp = new FindGoodsDaoImp();
        List good = findGoodsDaoImp.findGoods(sql);
        JSONArray json =JSONArray.fromObject(good);
        response.getWriter().print(json);
    }
}
